import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:text_gradiate/text_gradiate.dart';
import 'package:vape_xe/services/services.dart';
import 'package:vape_xe/utils/utils.dart';
import 'package:vape_xe/values/values.dart';

import 'logic.dart';

class WithdrawListView extends GetView<WithdrawListController> {
  const WithdrawListView({super.key});

  Widget _inviteItem(int index) {
    return Container(
      height: 120.h,
      padding: EdgeInsets.symmetric(horizontal: 16.w),
      decoration: BoxDecoration(
        borderRadius: 12.radius,
        color: Colors.white10,
      ),
      margin: EdgeInsets.only(left: 16.w, bottom: 12.h, right: 16.w),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              TextGradiate(
                text: Text(
                  controller.getStatusString(index),
                  style: TextStyle(fontSize: 12.sp, fontFamily: 'Montserrat'),
                ),
                colors: controller.withdrawList[index]['state'] == 2
                    ? const [Color(0xffF5B946), Color(0xffF58546)]
                    : controller.withdrawList[index]['state'] == 3
                        ? const [Color(0xffE71B1B), Color(0xffE71B1B)]
                        : [AppColors.secondaryText, AppColors.secondaryText],
                gradientType: GradientType.linear,
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
                tileMode: TileMode.clamp,
              ),
              const Spacer(),
              Row(
                crossAxisAlignment: CrossAxisAlignment.end,
                children: [
                  Padding(
                    padding: EdgeInsets.only(bottom: 3.h),
                    child: Text(
                      ConfigStore.to.currency,
                      style: TextStyle(
                        fontSize: 12.sp,
                        fontFamily: 'Montserrat',
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                  Text(
                    controller.withdrawList[index]['money'].toString().removeZero(),
                    style: TextStyle(
                      fontSize: 20.sp,
                      fontFamily: 'Montserrat',
                      fontWeight: FontWeight.bold,
                    ),
                  )
                ],
              ),
            ],
          ),
          Text(
            '${'Method'.tr}: ${controller.withdrawList[index]['accountType'] == 3 ? 'DuitNow' : 'USDT'}',
            style: TextStyle(fontSize: 11.sp, fontFamily: 'Montserrat', color: AppColors.secondaryText),
          ),
          Text(
            '${'Address'.tr}: ${controller.withdrawList[index]['account']}',
            style: TextStyle(fontSize: 11.sp, fontFamily: 'Montserrat', color: AppColors.secondaryText),
          ),
          Text(
            '${'Date'.tr}: ${controller.withdrawList[index]['createDateTimeStr']}',
            style: TextStyle(fontSize: 11.sp, fontFamily: 'Montserrat', color: AppColors.secondaryText),
          ),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios_new_rounded),
          onPressed: () => {Navigator.of(context).pop('刷新')},
        ),
        title: Text("Withdraw".tr),
      ),
      body: SmartRefresher(
        enablePullUp: true,
        physics: const BouncingScrollPhysics(),
        controller: controller.refreshController,
        onRefresh: controller.onRefresh,
        onLoading: controller.onLoading,
        child: Obx(
          () => controller.withdrawList.isEmpty
              ? SizedBox(height: 200.h, child: Center(child: Text('Empty list'.tr)))
              : ListView.builder(
                  itemCount: controller.withdrawList.length,
                  shrinkWrap: true, // 防止 ListView 自身滚动
                  physics: const NeverScrollableScrollPhysics(), // 禁止 ListView 自身滚动
                  itemBuilder: (context, index) => GestureDetector(
                    onTap: () => controller.toDetail(index),
                    child: _inviteItem(index),
                  ),
                ),
        ),
      ),
    );
  }
}
